package com.lyt.springboot.util.test;

import java.util.ArrayList;
import java.util.List;

public class BService {
    Aservice aservice = new Aservice();

    public List<Integer> get(List<Integer> ids) {
        if (ids.size() < 0 || ids.size() > 100) {
            throw new RuntimeException("异常");
        }
        List<Integer> result = new ArrayList<>();
        //分批操作
        for (List<Integer> batchId : partion(ids, 10)) {
            List<Integer> list = aservice.get(batchId);
            result.addAll(list);
        }
        return result;
    }

    public static <T> List<List<T>> partion(List<T> list, Integer size) {
        List<List<T>> part = new ArrayList<>();
        for (int i = 0; i < list.size(); i += size) {
            part.add(new ArrayList<>(list.subList(i, Math.min(i + size, list.size()))));
        }
        return part;
    }

    class Aservice {
        public List<Integer> get(List<Integer> ids) {
            //获取数据
            List<Integer> list1 = new ArrayList<>();
            return list1;
        }
    }
}